<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta charset="utf-8"/>
    <title>jqGrid - Ace Admin</title>

    <meta name="description" content="Dynamic tables and grids using jqGrid plugin"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

    <!-- bootstrap & fontawesome -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css"/>

    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="assets/css/jquery-ui.min.css"/>
    <link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css"/>
    <link rel="stylesheet" href="assets/css/ui.jqgrid.min.css"/>

    <!-- text fonts -->
    <link rel="stylesheet" href="assets/css/fonts.googleapis.com.css"/>

    <!-- ace styles -->
    <link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style"/>

    <!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet"/>
    <![endif]-->
    <link rel="stylesheet" href="assets/css/ace-skins.min.css"/>
    <link rel="stylesheet" href="assets/css/ace-rtl.min.css"/>

    <!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css"/>
    <![endif]-->

    <!-- inline styles related to this page -->

    <!-- ace settings handler -->
    <script src="assets/js/ace-extra.min.js"></script>

    <!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

    <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
    <script src="assets/angular/common-htm.js"></script>

    <!--[if lte IE 8]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->

    <style type="text/css">

    </style>
</head>

<body class="no-skin" ng-app="myApp" ng-controller="myCtrl">

<div id="navbar" class="navbar navbar-default ace-save-state">
    <div class="navbar-container ace-save-state common-head" id="navbar-container">

    </div><!-- /.navbar-container -->
</div>

<div class="main-container ace-save-state" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.loadState('main-container')
        } catch (e) {
        }
    </script>

    <div id="sidebar" class="sidebar responsive ace-save-state">
        <script type="text/javascript">
            try {
                ace.settings.loadState('sidebar')
            } catch (e) {
            }
        </script>

        <ul class="nav nav-list common-menu">
        </ul><!-- /.nav-list -->

        <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
            <i id="sidebar-toggle-icon" class="ace-icon fa fa-angle-double-left ace-save-state"
               data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
        </div>
    </div>

    <div class="main-content">
        <div class="main-content-inner">
            <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="ace-icon fa fa-home home-icon"></i>
                        <a href="#">首页</a>
                    </li>
                    <li><a href="#">支付管理</a></li>
                    <li><a href="#">应用管理</a></li>
                    <li class="active">应用支付配置</li>
                </ul><!-- /.breadcrumb -->

            </div>

            <div class="page-content">
                <div class="page-header">
                    <h1>
                        应用管理
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            应用支付信息配置
                        </small>
                    </h1>
                </div><!-- /.page-header -->

                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="merchantName"> 商户名称 </label>
                                <div class="col-sm-9">
                                    <input readonly="" type="text" class="col-xs-10 col-sm-5" id="merchantName"
                                           value=""/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="appName"> 应用名称 </label>
                                <div class="col-sm-9">
                                    <input readonly="" type="text" class="col-xs-10 col-sm-5" id="appName" value=""/>
                                    <input readonly="" type="hidden" class="col-xs-10 col-sm-5" id="appId" value=""/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="appSecret"> 应用签名密钥 </label>
                                <div class="col-sm-9">
                                    <input readonly="" type="text" class="col-xs-10 col-sm-5" id="appSecret" value=""/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="appNotifyUrl">
                                    支付回调地址 </label>
                                <div class="col-sm-9">
                                    <input readonly="" type="text" class="col-xs-10 col-sm-8" id="appNotifyUrl"
                                           value=""/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="appRefundNotifyUrl">
                                    退款通知地址 </label>
                                <div class="col-sm-9">
                                    <input readonly="" type="text" class="col-xs-10 col-sm-8" id="appRefundNotifyUrl"
                                           value=""/>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">支付配置：</label>
                                <div class="col-sm-2" id="thirdpartPayType_1">
                                    支付宝mapi支付:
                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_1" type="radio" class="ace" checked/>
                                            <span class="lbl"> 请选择 </span>
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_1" type="radio" class="ace"/>
                                            <span class="lbl"> radio option 1 </span>
                                        </label>
                                    </div>


                                </div>

                                <div class="col-sm-2" id="thirdpartPayType_2">
                                    支付宝app支付:
                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_2" type="radio" class="ace" checked/>
                                            <span class="lbl"> 请选择 </span>
                                        </label>
                                    </div>

                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_2" type="radio" class="ace"/>
                                            <span class="lbl"> radio option 2</span>
                                        </label>
                                    </div>

                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_2" type="radio" class="ace"/>
                                            <span class="lbl"> radio option 2-1</span>
                                        </label>
                                    </div>
                                </div>

                                <div class="col-sm-2" id="thirdpartPayType_11">
                                    微信公众支付:
                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_11" type="radio" class="ace" checked/>
                                            <span class="lbl"> 请选择 </span>
                                        </label>
                                    </div>

                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_11" type="radio" class="ace"/>
                                            <span class="lbl"> radio option 11</span>
                                        </label>
                                    </div>

                                </div>

                                <div class="col-sm-2" id="thirdpartPayType_12">
                                    微信开放平台支付:
                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_12" type="radio" class="ace" checked/>
                                            <span class="lbl"> 请选择 </span>
                                        </label>
                                    </div>

                                    <div class="radio">
                                        <label>
                                            <input name="thirdpartPayType_12" type="radio" class="ace"/>
                                            <span class="lbl"> radio option 12</span>
                                        </label>
                                    </div>
                                </div>

                            </div>


                            <div class="space-4"></div>

                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="button" id="saveBtn">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="button" id="rebackBtn">
                                        <i class="ace-icon fa fa-undo bigger-110"></i>
                                        返回
                                    </button>
                                </div>
                            </div>

                        </form>


                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div>

            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->


    <div class="footer common-footer"></div>

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div><!-- /.main-container -->

<!-- basic scripts -->

<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>

<!-- <![endif]-->

<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]-->
<script type="text/javascript">
    if ('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script src="assets/js/bootstrap.min.js"></script>

<!-- page specific plugin scripts -->
<script src="assets/js/bootstrap-datepicker.min.js"></script>
<script src="assets/js/jquery.jqGrid.min.js"></script>
<script src="assets/js/grid.locale-en.js"></script>

<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>

<!-- inline scripts related to this page -->
<script src="assets/js/atomu/common.js"></script>
<script type="text/javascript">

    var urlId = getUrlParam("id");

    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        //console.log(window.location.search);
        var r = window.location.search.substr(1).match(reg); //匹配目标参数
        if (r != null)
            return unescape(r[2]);
        return null; //返回参数值
    }

    //console.log('id='+urlId+' ');
    getMerchantInfo();

    $("#rebackBtn").click(function () {
        window.location.href = "app-list.html";
    });

    $("#saveBtn").click(function () {
        saveData();
    });

    //查询应用支付配置信息
    function getMerchantInfo() {
        getAjaxProxy("/atomu/v1/merchantApp/queryConfigInfo",
            'id=' + urlId,
            function (data) {
                var appConfig = data.data[0];
                initData(appConfig);
                return;
            });

    }

    function initData(appConfig) {
        $("#appId").val(appConfig.appId);
        $("#appName").val(appConfig.appName);
        $("#appSecret").val(appConfig.appSecret);
        $("#merchantName").val(appConfig.merchantName);
        $("#appNotifyUrl").val(appConfig.appNotifyUrl);
        $("#appRefundNotifyUrl").val(appConfig.appRefundNotifyUrl);

        //处理单选框
        var appConfigList = appConfig.appConfigList;
        var alipayList = appConfig.alipayList;
        var alipayAppList = appConfig.alipayAppList;
        var wechatOpenList = appConfig.wechatOpenList;
        var wechatPublicList = appConfig.wechatPublicList;

        dealRadio(appConfigList, alipayList, "thirdpartPayType_1");
        dealRadio(appConfigList, alipayAppList, "thirdpartPayType_2");
        dealRadio(appConfigList, wechatOpenList, "thirdpartPayType_11");
        dealRadio(appConfigList, wechatPublicList, "thirdpartPayType_12");
    }

    function dealRadio(configlist, dataList, idStr) {
        if (!dataList) {
            $("#" + idStr).hide();
        } else {
            var thirdpartPayType = Number(idStr.split("_")[1]);
            var radioStr = '';
            var hasData = false;
            for (var i = 0; i < configlist.length; i++) {
                if (configlist[i].thirdpartPayType == thirdpartPayType) {
                    hasData = true;
                    break;
                }
            }

            if (hasData) {
                var inData = false;
                for (var i = 0; i < dataList.length; i++) {
                    var checkedStr = "";
                    for (var j = 0; j < configlist.length; j++) {
                        if (configlist[j].thirdpartPayId == dataList[i].id) {
                            checkedStr = "checked";
                            inData = true;
                        }
                    }
                    var text = dataList[i].name;
                    if (!text) {
                        text = dataList[i].id; //名字不存在时显示id值
                    }
                    radioStr += '<div class="radio">' +
                        '<label>' +
                        '<input name="' + idStr + '" type="radio" class="ace" value="' + dataList[i].id + '" ' + checkedStr + '/>' +
                        '<span class="lbl"> ' + text + ' </span>' +
                        '</label>' +
                        '</div>';

                }
                var checkedStr = "";
                if (inData) {
                    checkedStr = "checked";
                }
                radioStr = '<div class="radio">' +
                    '<label>' +
                    '<input name="' + idStr + '" type="radio" class="ace" value="" ' + checkedStr + ' />' +
                    '<span class="lbl"> 请选择</span>' +
                    '</label>' +
                    '</div>'
                    + radioStr;

            } else {
                radioStr += '<div class="radio">' +
                    '<label>' +
                    '<input name="' + idStr + '" type="radio" class="ace" value="" checked/>' +
                    '<span class="lbl"> 请选择 </span>' +
                    '</label>' +
                    '</div>';

                for (var i = 0; i < dataList.length; i++) {
                    radioStr += '<div class="radio">' +
                        '<label>' +
                        '<input name="' + idStr + '" type="radio" class="ace" value="' + dataList[i].id + '"/>' +
                        '<span class="lbl"> ' + dataList[i].id + ' </span>' +
                        '</label>' +
                        '</div>';
                }
            }
            //console.log(radioStr);
            $("#" + idStr).find("div").remove();
            $("#" + idStr).append(radioStr);

        }
    }

    function saveData() {
        var appId = $("#appId").val();
        var thirdpartPayType_1 = $("#thirdpartPayType_1").find("input[type=radio]:checked").val();
        var thirdpartPayType_2 = $("#thirdpartPayType_2").find("input[type=radio]:checked").val();
        var thirdpartPayType_11 = $("#thirdpartPayType_11").find("input[type=radio]:checked").val();
        var thirdpartPayType_12 = $("#thirdpartPayType_12").find("input[type=radio]:checked").val();

        var datas = {};
        var payInfoList = [{"thirdpartPayType": 1, "thirdpartPayId": thirdpartPayType_1},
            {"thirdpartPayType": 2, "thirdpartPayId": thirdpartPayType_2},
            {"thirdpartPayType": 11, "thirdpartPayId": thirdpartPayType_11},
            {"thirdpartPayType": 12, "thirdpartPayId": thirdpartPayType_12}
        ];

        datas.appId = appId;
        datas.configList = payInfoList;
        var param = JSON.stringify(datas);

        postAjaxProxy("/atomu/v1/merchantApp/saveConfigInfo", param,
            function (data) {
                alert("保存成功");
                return;
            });
    }


    menuArr[0].child[1].isActive = true;
    // var userInfo = getUserInfo();
    var initData = {"moduleId": "myApp", "menuObj": menuArr, "curUserName": "userInfo.account"};
    commonHtml.dealCommonHtml(initData);

</script>
</body>
</html>
